<template>
	<view class="page bg-white">
		<view class="main">
			<!-- 选择要加入的班级 -->
			<u-text color="#333" size="32rpx" text="报名班级" bold></u-text>
			<view class="form-item" @click="showClassPicker = true">
				<u-text :text="formData.classInfo || '请选择报名班级'" size="32rpx"
					:color="formData.classInfo ? '#333' : '#999'"></u-text>
				<u-icon name="arrow-down" size="32rpx" color="#999"></u-icon>
			</view>

			<!-- 报名周期 -->
			<u-text margin="60rpx 0 0 0" color="#333" size="32rpx" text="报名日期" bold></u-text>
			<view class="flex gap">
				<view class="form-item flex-1" @click="showStartDate = true">
					<u-text :text="formData.startDate ? dayjs(formData.startDate).format('YYYY-MM-DD') : '请选择开始日期'" size="32rpx"
						:color="formData.startDate ? '#333' : '#999'"></u-text>
					<u-icon name="calendar" size="36rpx" color="#999"></u-icon>
				</view>
				<view class="form-item flex-1" @click="showEndDate = true">
					<u-text :text="formData.endDate ? dayjs(formData.endDate).format('YYYY-MM-DD') : '请选择结束日期'" size="32rpx"
						:color="formData.endDate ? '#333' : '#999'"></u-text>
					<u-icon name="calendar" size="36rpx" color="#999"></u-icon>
				</view>
			</view>

			<!-- 学生姓名 -->
			<u-text margin="60rpx 0 0 0" color="#333" size="32rpx" text="学生姓名" bold></u-text>
			<view class="margin-top-sm">
				<u-input customStyle="height:80rpx;border-radius:20rpx" fontSize="32rpx" v-model="formData.studentName"
					placeholder="请输入学生姓名"></u-input>
			</view>

			<!-- 学生性别	 -->
			<u-text margin="60rpx 0 0 0" color="#333" size="32rpx" text="选择学生性别" bold></u-text>
			<view class="margin-top-sm">
				<up-radio-group gap="40rpx" size="32rpx" v-model="formData.studentGender">
					<up-radio labelSize="32rpx" active-color="#FFB74D" v-for="(item, index) in sexOptions" :key="item.value"
						:label="item.label" :name="item.value" />
				</up-radio-group>
			</view>

			<!-- 监护人/接送人	 -->
			<u-text margin="60rpx 0 0 0" color="#333" size="32rpx" text="选择监护人/接送人" bold></u-text>
			<view>
				<view class="flex gap margin-top-sm" v-for="(item, index) in formData.guardians" :key="index">
					<view style="flex:0.8">
						<u-input customStyle="height:80rpx;border-radius:20rpx" fontSize="32rpx"
							v-model="formData.guardians[index].name" placeholder="主监护人称呼"></u-input>
					</view>
					<view class="flex-1">
						<u-input customStyle="height:80rpx;border-radius:20rpx" fontSize="32rpx"
							v-model="formData.guardians[index].phone" placeholder="主监护人联系方式"></u-input>
					</view>
				</view>
				<view class="margin-top-sm">
					<u-button size="large" shape="circle" :color="themeTertiary"
						:customStyle="{ fontSize: '30rpx', color: themePrimary }" text="新增" @click="addGuardian"></u-button>
				</view>
			</view>

			<!-- 学员照片	 -->
			<u-text margin="60rpx 0 0 0" color="#333" size="32rpx" text="学员照片" bold></u-text>
			<view>
				<UploadBox placeholder="点击上传照片" />
			</view>

			<!-- 学生出生日期	 -->
			<u-text margin="60rpx 0 0 0" color="#333" size="32rpx" text="学生出生日期" bold></u-text>
			<view class="form-item" @click="showBirthdate = true">
				<u-text :text="formData.birthday ? dayjs(formData.birthday).format('YYYY-MM-DD') : '请选择学生出生日期'" size="32rpx"
					:color="formData.birthday ? '#333' : '#999'"></u-text>
				<u-icon name="calendar" size="36rpx" color="#999"></u-icon>
			</view>

			<!-- 家庭住址	 -->
			<u-text margin="60rpx 0 0 0" color="#333" size="32rpx" text="学生家庭住址" bold></u-text>
			<view class="margin-top-sm">
				<u-input customStyle="height:80rpx;border-radius:20rpx" fontSize="32rpx" v-model="formData.address"
					placeholder="请输入学生家庭住址"></u-input>
			</view>

			<!-- 就读学校	 -->
			<u-text margin="60rpx 0 0 0" color="#333" size="32rpx" text="学生就读学校" bold></u-text>
			<view class="margin-top-sm">
				<u-input customStyle="height:80rpx;border-radius:20rpx" fontSize="32rpx" v-model="formData.school"
					placeholder="请输入就读学校"></u-input>
			</view>
			<!-- 就读年级	 -->
			<u-text margin="60rpx 0 0 0" color="#333" size="32rpx" text="学生就读年级" bold></u-text>
			<view class="margin-top-sm">
				<u-input customStyle="height:80rpx;border-radius:20rpx" fontSize="32rpx" v-model="formData.grade"
					placeholder="请输入就读年级"></u-input>
			</view>

			<!-- 就读班级	 -->
			<u-text margin="60rpx 0 0 0" color="#333" size="32rpx" text="学生就读班级" bold></u-text>
			<view class="margin-top-sm">
				<u-input customStyle="height:80rpx;border-radius:20rpx" fontSize="32rpx" v-model="formData.className"
					placeholder="请输入就读班级"></u-input>
			</view>

			<!-- 近期成绩录入	 -->
			<u-text margin="60rpx 0 0 0" color="#333" size="32rpx" text="近期成绩录入" bold></u-text>
			<view class="margin-top-sm">
				<view class="form-item" @click="showRecentScoreType = true">
					<u-text :text="formData.recentScoreType ? formData.recentScoreType : '请选择考试类型'" size="32rpx"
						:color="formData.recentScoreType ? '#333' : '#999'"></u-text>
					<u-icon name="arrow-down" size="36rpx" color="#999"></u-icon>
				</view>
				<view class="form-item" @click="showRecentScoreType = true">
					<text class="text-lg">语文</text>
					<u-input customStyle="height:30rpx;" fontSize="32rpx" v-model="formData.chineseScore"
						placeholder="请输入语文成绩"></u-input>
				</view>
				<view class="form-item" @click="showRecentScoreType = true">
					<text class="text-lg">数学</text>
					<u-input customStyle="height:30rpx;" fontSize="32rpx" v-model="formData.mathScore"
						placeholder="请输入数学成绩"></u-input>
				</view>
				<view class="form-item" @click="showRecentScoreType = true">
					<text class="text-lg">英语</text>
					<u-input customStyle="height:30rpx;" fontSize="32rpx" v-model="formData.englishScore"
						placeholder="请输入英语成绩"></u-input>
				</view>
			</view>

			<!-- 选择要加入的班级弹窗 -->
			<up-picker :closeOnClickOverlay="true" :show="showClassPicker" :columns="classList"
				@close="showClassPicker = false" @confirm="handleClassConfirm"></up-picker>

			<!-- 开始时间选择器 -->
			<up-datetime-picker :closeOnClickOverlay="true" :show="showStartDate" mode="date" format="YYYY-MM-DD"
				@cancel="showStartDate = false" @confirm="handleStartDateConfirm"></up-datetime-picker>
			<!-- 结束时间选择器 -->
			<up-datetime-picker :closeOnClickOverlay="true" :show="showEndDate" mode="date" format="YYYY-MM-DD"
				@cancel="showEndDate = false" @confirm="handleEndDateConfirm"></up-datetime-picker>
			<!-- 出生日期 -->
			<up-datetime-picker :closeOnClickOverlay="true" :show="showBirthdate" mode="date" format="YYYY-MM-DD"
				@cancel="showBirthdate = false" @confirm="handleBirthdateConfirm"></up-datetime-picker>

			<!-- 考试类型弹窗 -->
			<up-picker :closeOnClickOverlay="true" :show="showRecentScoreType" :columns="recentScoreTypeList"
				@close="showRecentScoreType = false" @confirm="handleRecentScoreTypeConfirm"></up-picker>
		</view>
		<view class="footer" :style="{ boxShadow: '0rpx -4rpx 36rpx 0rpx ' + themeTertiary }">
			<u-button shape="circle" size="large" :color="themePrimary" text="保存"></u-button>
		</view>

	</view>
</template>
<script setup>
import { ref } from 'vue'
import { useTheme } from '@/composables/useTheme';
import dayjs from 'dayjs';
import UploadBox from '@/components/UploadBox/index.vue';
const { themePrimary, themeSecondary, themeTertiary } = useTheme();

// 报名周期弹窗
const showStartDate = ref(false)
const showEndDate = ref(false)
const showBirthdate = ref(false)
// 近期成绩录入弹窗
const showRecentScoreType = ref(false)
// 近期成绩录入类型列表
const recentScoreTypeList = ref([['期中考试', '期末考试', '月考', '单元考试']])

const formData = ref({
	startDate: '',
	endDate: '',
	classInfo: null,
	studentInfo: null,
	birthday: '',
	guardians: [],
	recentScoreType: null, //近期成绩录入类型
	chineseScore: '',
	mathScore: '',
	englishScore: ''
})
// 报名班级弹窗
const showClassPicker = ref(false)

// 班级列表
const classList = ref([['托管班：一年级（A）班', '周末班：一年级-数学（A）班']])

// 性别列表
const sexOptions = ref([
	{
		label: '男',
		value: '男'
	},
	{
		label: '女',
		value: '女'
	}
])

// 班级选择器确认
const handleClassConfirm = (e) => {
	console.log(e)
	showClassPicker.value = false
	formData.value.classInfo = e.value[0]
}

// 开始日期选择器确认
const handleStartDateConfirm = (e) => {
	console.log(e)
	showStartDate.value = false
	formData.value.startDate = e.value
}

// 结束日期选择器确认
const handleEndDateConfirm = (e) => {
	console.log(e)
	showEndDate.value = false
	formData.value.endDate = e.value
}

// 出生日期选择器确认
const handleBirthdateConfirm = (e) => {
	console.log(e)
	showBirthdate.value = false
	formData.value.birthday = e.value
}

// 近期成绩录入类型确认
const handleRecentScoreTypeConfirm = (e) => {
	console.log(e)
	showRecentScoreType.value = false
	formData.value.recentScoreType = e.value[0]
}

const addGuardian = () => {
	console.log('addGuardian')
	formData.value.guardians.push({
		name: '',
		phone: ''
	})
}
</script>
<style scoped lang="scss">
.form-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	background: #F7F7F7;
	padding: 30rpx;
	margin-top: 20rpx;
	border-radius: 20rpx;
}

.camera-icon {
	position: absolute;
	bottom: 0;
	right: 0;
	width: 54rpx;
	height: 54rpx;
}
</style>